package com.glacier.demo.handle;

import com.alibaba.csp.sentinel.Tracer;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.glacier.framework.component.dto.response.Response;
import com.glacier.framework.component.dto.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * date 2024-01-30 21:11
 *
 * @author glacier
 * @version 1.0
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandle {

//    @ExceptionHandler(value = {FlowException.class})
//    public Response<String> flowException(FlowException ex) {
//        log.info("服务限流了", ex);
//        // 记录异常信息到Sentinel中
//        Tracer.trace(ex);
//        return Response.error(StatusCode.SERVICE_THROTTLING);
//    }

//    @ExceptionHandler(value = {Exception.class})
//    public Response<String> exception(Exception ex) {
//        log.info("出现异常", ex);
//        // 记录异常信息到Sentinel中
//        Tracer.trace(ex);
//        // 处理异常并返回响应
//        return Response.error(StatusCode.INTERNAL_SERVER_ERROR);
//    }
}
